package com.jiazhong.IO流.字节到字符的转换流;

import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStreamReader;

public class InputStreamReaderDemo {
    public static void main(String[] args) throws IOException {

        //创建字节输入流对象(仅限使用utf-8)，无法设置编码
        FileInputStream fileInputStream = new FileInputStream("D:\\Study\\MySQL8\\mysql-8.0.26-winx64\\mysql-8.0.26-winx64\\安装说明.txt");
        //创建字节到字符输入流对象,转换流默认使用UTF-8编码转换
        //该流会自动将字节流读到的字节数据转换字符数据并根据指定的编码进行转换
        InputStreamReader inputStreamReader = new InputStreamReader(fileInputStream, "utf-8");

        char[] buf = new char[1024];
        int len = -1;
        while ((len = inputStreamReader.read(buf)) != -1) {
            String str = String.valueOf(buf,0,len);
            System.out.println(str);
        }
        inputStreamReader.close();

    }
}
